﻿#include "AddBCAction.h"
#include "Application.h"
#include "System.h"
#include "UserObject.h"

void AddBCAction::Execute()
{
  std::vector<std::string> bcs;
  for (auto& section : _parser.cf().get_section_names())
  {
    if (section.find("BCs/") != section.npos)
    {
      if (section != "BCs/")   //忽略BCs
      {
        bcs.push_back(section);
      }
    }
  }


  Configuration cfg;
  cfg.Add<Application*>("_app", &_app);
  cfg.Add<Parser*>("_parser", &_parser);
  auto sys = _app.GetSystem();
  if (!sys)
    Error("System未创建.");

  for (auto& bc : bcs)
  {
    _parser.SetPrefix(bc);
    auto type = cfg.Get<std::string>("type");
    auto boundary = cfg.GetVectorValue<std::string>("boundary");

    std::cout << type << ": ";
    std::for_each(boundary.begin(), boundary.end(), [](auto& v) { std::cout << v << " "; });
    std::cout << std::endl;

    sys->AddBoundaryCondition({ type, boundary });
  }

  Success("AddBCAction");
}